package com.zq;

import org.junit.jupiter.api.Test;

import java.util.Comparator;
import java.util.HashMap;
import java.util.TreeMap;

/**
 * @ProjectName: ybxy6
 * @Titile: TreeMap
 * @Author: zqsfg
 * @Description: TODO
 */
public class TreeMapDemo {
    public static void main(String[] args) {
//        test1();
//        test2();


    }

    private static void test1() {
        TreeMap<Student, String> treeMap = new TreeMap<>();

        treeMap.put(new Student("李四", 19), "上海");
        treeMap.put(new Student("孙七", 22), "深圳");
        treeMap.put(new Student("张三", 18), "四川");
        treeMap.put(new Student("王五", 20), "北京");
        treeMap.put(new Student("赵六", 21), "广州");
        treeMap.forEach((key, value)->{
            System.out.println(key+"="+value);
        });

        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("zsq", "四川");
    }
    private static void test2() {

        TreeMap<Student, String> treeMap = new TreeMap<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                //倒序
                return o2.getAge()-o1.getAge();
            }
        });

        treeMap.put(new Student("孙七", 22), "深圳");
        treeMap.put(new Student("张三", 18), "四川");
        treeMap.put(new Student("王五", 20), "北京");
        treeMap.put(new Student("赵六", 21), "广州");
        treeMap.put(new Student("李四", 19), "上海");
        treeMap.forEach((key, value)->{
            System.out.println(key+"="+value);
        });

    }

//单元测试方法
    @Test
    public  void  test3() {

        TreeMap<Student, String> treeMap = new TreeMap<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                //倒序
                return o2.getAge()-o1.getAge();
            }
        });

        treeMap.put(new Student("孙七", 22), "深圳");
        treeMap.put(new Student("张三", 18), "四川");
        treeMap.put(new Student("王五", 20), "北京");
        treeMap.put(new Student("赵六", 21), "广州");
        treeMap.put(new Student("李四", 19), "上海");
        treeMap.forEach((key, value)->{
            System.out.println(key+"="+value);
        });

    }


}
